<template>
  <div class="home" style="padding: 20px 0;">
    <ConfigTable :data="list" v-bind="config" v-loading="loading" />
  </div>
</template>

<script>
import axios from 'axios'
import CreateConfig from '@/config/table'
import ConfigTable from '@/components/jsx/Table'
import { loopExecution, sleep, loopUntil } from '@/utils/taskQueue'
export default {
  name: 'HomeView',
  components: {
    ConfigTable
  },
  data() {
    return {
      list: [],
      count: 0,
      xxx: 0,
      loading: false,
      config: CreateConfig.call(this),
    }
  },
  mounted() {
    this.getdata()
    // loopExecution(this.getTime, 3000, () => this.count)
    // loopUntil(this.testfun, () => this.xxx === 5, 3000)
    // loopExecution(this.testfun, 3000, () => this.xxx === 5)
  },
  methods: {
    async testfun(){
      console.log('xxxxxxx')
      await sleep(500)
      this.xxx++
    },
    currentChange(index) {
      this.getdata(index)
    },
    async getdata(i = 1) {
      this.loading = true
      const res = await axios.get('data.json')
      this.config.pagination.total = 1000
      this.list = this.config.api.handler(res.data)
      this.loading = false
    },
    async getTime() {
      await sleep(1000)
      this.count++
      console.log('xxxxxxx')
    }
  }
}
</script>